Custom Action Nodes /自定义活动节点

节点类型可以为:同步节点或异步节点

编写自定义活动节点

节点执行器必须继承 ActionExecutor并覆盖相应必须方法,

ActionExecutor.Context访问配置属性,设置节点状态,设置变量用于之后的执行路径

ActionExecutor需要实现的接口:

Constructor:无参构造函数,且必须调用super(ACTION_TYPE)ACTION_TYPE是在wf xml中使用的节点名称,并用于Oozie实例化为正确的Executor

initActionType():在活动Executor 初始化时调用,任何通用初始化代码都放这,例如,设置error处理,这个方法必须调用super.initActionType()作为最初状态,

start(ActionExecutor.Context context, Action action):节点启动在这:

Async Actions - The action should be started and context.setStartData(externalId, trackerUri, consoleUrl) must be set. A check can be made for whether the action has completed, in which case context.setExecutionData(externalStatus, actionData) must be called.
Sync Actions - The action should be started and should complete execution. context.setExecutionData(externalStatus, actionData) must be called.

check(ActionExecutor.Context context, Action action)

check(...) is used by Oozie to poll for the status of the action. This method should interact with the action started previously, and update the status. If the action has completed, context.setExecutionData(externalStatus, actionData) must be called. Otherwise, the status can be updated using context.setExternalStatus(externalStatus).

For sync actions, this method will not be called, and should throw an UnsupportedOperationException().

kill(ActionExecutor.Context context, Action action)

kill(...)is called when there is an attempt to kill the running job or action. No workflow transition is made after this.

The implementation for a custom action should interact with and kill the running action, and take care of any cleanup which may be required. context.setEndData(status, signalValue) should be called with both values set to Action.Status.KILLED.

end(ActionExecutor.Context context, Action action)

end(...) is used for any cleanup or processing which may need to be done after completion of the action. After any processing, context.setEndData(status, signalValue) should be called to complete execution of the action and trigger the next workflow transition. signalValue can be Action.Status.OK or Action.Status.ERROR.

Registereing Errors

Oozie actions can generate different types of Errors.

TRANSIENT - will be retried
NON TRANSIENT - the job will be suspended and can be resumed later by human intervention, after fixing whatever problem caused this error.
ERROR - causes the error transition to be taken.
FAILED - the action and the job are set to FAILED state. No transitions are taken.

registerError(exceptionClassName, errorType, errorMessage) can be used to register possible exceptions while executing the action, along with their type and error message. This will normally be done during initialization of the Action Executor.

Deploying a custom Action Executor

Action Nodes can be registered in the oozie configuration file oozie-site.xml, by changing the property 'oozie.service.ActionService.executor.ext.classes'. For multiple Executors, the class name should be separated by commas.

  <property>
    <name>oozie.service.ActionService.executor.ext.classes</name>
    <value>
      org.apache.oozie.wf.action.decision.CustomActionExecutor,
      Custom_Action_Executr_2.class
    </value>
  </property>

Any configuration properties to be made available to this class should also be added to oozie-site.xml. The convention to be followed for naming these properties is 'oozie.action.[ActionName].property.name'

The XML schema (XSD) for the new Actions should be added to oozie-site.xml, under the property 'oozie.service.WorkflowSchemaService.ext.schemas'. A comma separated list for multiple Action schemas.

The executor class should be placed along with the oozie webapp in the correct path. Once Tomcat is restarted, the custom action node can be used in workflows.